package top.syfy.demo.swagger.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.syfy.demo.swagger.pojo.User;

/**
 * @author syfy
 * @date 2021/04/30
 */
@RestController
@Api(description = "用户控制器,包含用户的保存/查询等功能")
public class UserController {


    /**
     * 用户注册
     *
     * @param user 用户类的对象
     * @return 用户注册的结果
     */
    @ApiOperation(value = "用户注册")
    @PostMapping(value = "/user")
    public String save(@RequestBody @ApiParam(name = "user", value = "用户类的对象", required = true) User user) {
        // do somethings
        return "success";
    }


    // 只要接口中返回值存在实体类，它就会被Swagger扫描到（即在 swagger-ui.html) 中可以看到实体类的相关信息, 即使其实体类没有使用Swagger的注解进行标识）
    /**
     * 根据用户ID查询用户信息
     *
     * @param uid 用户ID
     * @return 与用户ID匹配的用户信息
     */
    @ApiOperation(value = "根据用户ID查询用户信息")
    @GetMapping(value = "/user/{uid}")
    public User get(@PathVariable(name = "uid") @ApiParam(name = "uid", value = "用户ID", example = "1", required = true) Long uid) {
        // do somethings
        return new User();
    }
}
